#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char **argv)
{
    int fd;
    int val = 1;

    if(argc != 3){
        printf("param error!");
        return 0;
    }

    if(!strcmp(argv[1], "leds"))
    {
        fd = open("/dev/leds", O_RDWR);
    }
    else if(!strcmp(argv[1], "led1"))
    {
        fd = open("/dev/led1", O_RDWR);
    }
    else if(!strcmp(argv[1], "led2"))
    {
        fd = open("/dev/led2", O_RDWR);
    }
    else if(!strcmp(argv[1], "led3"))
    {
        fd = open("/dev/led3", O_RDWR);
    }
    else
    {
        printf("param error!");
        return 0;
    }

    if(fd < 0)
    {
        printf("can't open!\n");
        return 0;
    }

    if(!strcmp(argv[2], "on"))
    {
        val = 1;
    }
    else
    {
        val = 0;
    }

    write(fd, &val, sizeof(val));

    return 0;
}
